package edu.avans.hartigehap.service.jpa;

import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.google.common.collect.Lists;

import edu.avans.hartigehap.repository.*;
import edu.avans.hartigehap.service.*;
import edu.avans.hartigehap.domain.*;

@Service("discountService")
@Repository
@Transactional(rollbackFor = StateException.class)
public class DiscountServiceImpl implements DiscountService {
	final Logger logger = LoggerFactory.getLogger(DiscountServiceImpl.class);

	@Autowired
	private DiscountRepository discountRepository;
	
	/*
	@Transactional(readOnly=true)
	public List<Discount> findActiveDiscounts() {
		// a query created using a repository method name
		return discountRepository.findAllByActive();
	}*/

	@Transactional(readOnly=true)
	public List<Discount> findAll() {
		return Lists.newArrayList(discountRepository.findAll());
	}

	@Transactional(readOnly=true)
	public List<Discount> findAllByActive(Boolean active) {
		List<Discount> discounts = discountRepository.findByActive(active);
		return discounts;
	}

	/*
	@Transactional(readOnly=true)
	public List<Discount> findAllByActive(Boolean active) {
		// TODO Auto-generated method stub
		return Lists.newArrayList(discountRepository.findAllByActive(active));
	}*/
}
